%{
This file finds the static parameters to optimize the outcomes of within
period search
%}

%% Calibration exercise
function x = ds_optimization(State,psi,kh,ke,ka) 


%% Directed Search - one price - one period
% This version of the model the search happens as a one shot game and
% prices are determines via nash bargaining between and agent and a buyer.
% v here is determined by prices (matches prices exactly)
% lambd_1 and lamd_2 determines the level and dispersion of sale
% probabilities in experience
% all the other parameters are essentially redundant (can be "adjusted"
% with lambd_1. However to match the differential level of sale
% probabilities across aggregate states, we let c_b vary by state
% (alternatively could let gamma vary by state as well)
    

    lamb_12 = 1; % this was missing was 0.1
    lamb_13 = 1; % this was missing was 0.1
    lamb_2 = 0.03;
    c_b = 100000;
    params0 = [lamb_12, lamb_13, lamb_2, c_b];
    lb = [0.05,   0.05, 0.000000001, 3500];
    ub = [2, 2, 0.4, 200000];

    A   = []; b   = [];
    Aeq = []; beq = []; nonlcon = []; 
    
%    load obj_min_search_one_price_static_best.mat  params_min
%    params0 = [params_min];
    
    nvars = max(size(params0));
    delete('obj_min_search_one_price_static.mat')
    obj_min = 1000000000000000000;
    save obj_min_search_one_price_static.mat obj_min

    options = optimset('Display','on','TolFun', 1e-19,'TolX', 1e-19);
   x = fmincon(@obj_fun_urn_matching_one_price_static,params0,A,b,Aeq,beq,lb,ub);

    function y = obj_fun_urn_matching_one_price_static(params)
       y = ds_urn_matching_one_price_static(params,State,psi,kh,ke,ka,0); 
    end

end

